package org.example.springblogdemo.controller;

import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.example.springblogdemo.pojo.request.UserLoginRequest;
import org.example.springblogdemo.respone.UserInfoResponse;
import org.example.springblogdemo.respone.UserLoginResponse;
import org.example.springblogdemo.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/user")
@RestController
public class UserController {
    @Resource(name = "userServiceImpl")
    private UserService userService;
    @PostMapping("/login")
    public UserLoginResponse login(@Validated @RequestBody UserLoginRequest userLoginRequest){
        log.info("用户登录, userLoginRequest:{}", userLoginRequest);
        return userService.check(userLoginRequest);
    }
    @GetMapping("/getUserInfo")
    public UserInfoResponse getUserInfo(@NotNull Integer userId){
        log.info("获取用户信息, userId:{}", userId);
        return userService.getUserInfo(userId);
    }
    @GetMapping("/getAuthorInfo")
    public UserInfoResponse getAuthorInfo(@NotNull Integer blogId){
        log.info("获取作者信息, blogId:{}", blogId);
        return userService.getAuthorInfo(blogId);
    }
}
